#coding=utf-8
from django.views.decorators.csrf import csrf_exempt
from django.http import HttpResponse
from django.shortcuts import render
from django.shortcuts import render_to_response
import sys
import os
reload(sys)
sys.setdefaultencoding("utf8")

#首页
def Yidai_Test(request):
    return render_to_response('index.html')


#注册-co
def register(request):
    new_url = request.GET.get('url')
    new_phone = request.GET.get('phone')
    new_realname = request.GET.get('realname')
    new_username = request.GET.get('username')
    new_user_password = request.GET.get('user_password')
    import P2P_register
    #return HttpResponse(P2P_register.register(new_username, new_phone, new_password, new_imgCode, new_smsCode))
    return render(request, 'test_result.html', {'testmsg':P2P_register.register(new_url,new_phone,new_realname,new_username,new_user_password)})


#宜湃网环境发标-接口自动化
def yipaiwang(request):
    new_url = request.GET.get('url')
    new_adminname = request.GET.get('adminname')
    new_password = request.GET.get('password')
    new_borrowtype = request.GET.get('borrowtype')
    new_borrowtitle = request.GET.get('borrowtitle')
    new_money = request.GET.get('money')
    new_rate = request.GET.get('rate')
    new_username_type = request.GET.get('username_type')
    new_borrowname = request.GET.get('borrowname')
    new_huankuanfangshi = request.GET.get('huankuanfangshi')
    new_period_type = request.GET.get('period_type')
    new_month = request.GET.get('month')
    new_cashgroup = request.GET.get('cashgroup')
    new_agentname = request.GET.get('agentname')
    new_tender_account_min = request.GET.get('tender_account_min')
    new_pay_type = request.GET.get('pay_type')

    import Input
    #return HttpResponse( op_xyz.xyz_fang(new_adminname, new_password, new_borrowtitle, new_money, new_rate,new_username_type, new_borrowname, new_borrowmode,new_month,new_cashgroup, new_agentname, new_rewardstate, new_rewardmode, new_reward))
    return render(request, 'test_result.html', {'testmsg':Input.Input(new_url, new_adminname, new_password, new_borrowtype,new_borrowtitle, new_money, new_huankuanfangshi,new_rate, new_username_type,new_borrowname,new_period_type,new_month,new_cashgroup,new_agentname,new_tender_account_min,new_pay_type)})



#宜贷网环境发标-接口自动化
def yidai(request):
    new_url = request.GET.get('url')
    new_adminname = request.GET.get('adminname')
    new_password = request.GET.get('password')
    new_borrowtype = request.GET.get('borrowtype')
    new_borrowtitle = request.GET.get('borrowtitle')
    new_money = request.GET.get('money')
    new_rate = request.GET.get('rate')
    new_username_type = request.GET.get('username_type')
    new_borrowname = request.GET.get('borrowname')
    new_huankuanfangshi = request.GET.get('huankuanfangshi')
    new_month = request.GET.get('month')
    new_cashgroup = request.GET.get('cashgroup')
    new_agentname = request.GET.get('agentname')
    new_borrow_fee_rate = request.GET.get('borrow_fee_rate')
    import P2P_input
    #return HttpResponse( op_xyz.xyz_fang(new_adminname, new_password, new_borrowtitle, new_money, new_rate,new_username_type, new_borrowname, new_borrowmode,new_month,new_cashgroup, new_agentname, new_rewardstate, new_rewardmode, new_reward))
    return render(request, 'test_result.html', {'testmsg':P2P_input.Input(new_url, new_adminname, new_password, new_borrowtype,new_borrowtitle, new_money, new_huankuanfangshi,new_rate, new_username_type,new_borrowname,new_month,new_cashgroup,new_agentname,new_borrow_fee_rate)})

#计划任务页面
def task(request):
    return render(request, 'task.html')

#执行计划任务程序
def task_do(request):
    new_url = request.GET.get('url')
    import task
    return render(request, 'test_result.html',{'testmsg':task.task(new_url)})

def task_manbiao(request):
    new_url = request.GET.get('url')
    new_borrowid = request.GET.get('borrowid')
    new_date = request.GET.get('date')
    import task
    return render(request, 'test_result.html',{'testmsg':task.task_manbiao(new_url,new_borrowid,new_date)})

def task_yuqi(request):
    new_url = request.GET.get('url')
    new_user_id = request.GET.get('user_id')
    import task
    return render(request, 'test_result.html',{'testmsg':task.task_yuqi(new_url,new_user_id)})


def task_tixian_1(request):
    new_url = request.GET.get('url')
    import task
    return render(request, 'test_result.html', {'testmsg': task.task_tixian_1(new_url)})

def task_tixian_2(request):
    new_url = request.GET.get('url')
    import task
    return render(request, 'test_result.html', {'testmsg': task.task_tixian_2(new_url)})

def task_tixian(request):
    new_url = request.GET.get('url')
    new_status = request.GET.get('status')
    new_log_num = request.GET.get('log_num')
    import task
    return render(request, 'test_result.html',{'testmsg':task.task_tixian(new_url,new_status,new_log_num)})

#随机生成银行卡号
def banid(request):
    import bankid
    return render(request, 'test_result.html', {'testmsg':bankid.bankid()})

#随机生成身份证号码
def IDcard(request):
    import ID_card
    return render(request, 'test_result.html', {'testmsg':ID_card.idcard_generator()})

#财务系统上账
def shangzhang(request):
    new_url = request.GET.get('url')
    new_adminname = request.GET.get('adminname')
    new_phone = request.GET.get('phone')
    new_password = request.GET.get('password')
    new_username = request.GET.get('username')
    new_money = request.GET.get('money')
    import cw
    return render(request,'test_result.html', {'testmsg':cw.cw_shangzhang(new_url,new_adminname,new_phone,new_password,new_username,new_money)})

#优+额度公式计算
def eshare(request):
    new_url = request.GET.get('url')
    new_user_id = request.GET.get('user_id')
    import eshare
    return render(request, 'test_result.html', {'testmsg': eshare.eshare(new_url,new_user_id)})

#实名认证+绑卡
def bangka(request):
    new_url = request.GET.get('url')
    new_keywords = request.GET.get('keywords')
    new_password = request.GET.get('password')
    new_realname = request.GET.get('realname')
    import P2P_register
    return render(request, 'test_result.html', {'testmsg': P2P_register.bangka(new_url, new_keywords,new_password,new_realname)})

#查询用户user_id接口
def find_user_id(request):
    new_url = request.GET.get('url')
    new_usertype = request.GET.get('usertype')
    new_phone = request.GET.get('phone')
    import P2P_register
    return render(request, 'test_result.html',{'testmsg': P2P_register.find_user_id(new_url, new_usertype,new_phone)})

#发放红包接口
def Redenvelopes(request):
    new_url = request.GET.get('url')
    new_envelopes_id = request.GET.get('envelopes_id')
    new_phone = request.GET.get('phone')
    new_laiyuan = request.GET.get('laiyuan')
    import P2P_register
    return render(request, 'test_result.html', {'testmsg': P2P_register.Redenvelopes(new_url, new_envelopes_id, new_phone,new_laiyuan)})

#发放加息券接口
def increasecoupon(request):
    new_url = request.GET.get('url')
    new_envelopes_id = request.GET.get('envelopes_id')
    new_phone = request.GET.get('phone')
    new_laiyuan = request.GET.get('laiyuan')
    import P2P_register
    return render(request, 'test_result.html', {'testmsg': P2P_register.increasecoupon(new_url, new_envelopes_id, new_phone,new_laiyuan)})

#计算罚息接口
def faxi(request):
    new_benjin = request.GET.get('benjin')
    new_rate = request.GET.get('rate')
    new_today = request.GET.get('today')
    new_enddate = request.GET.get('enddate')
    import task
    return render(request, 'test_result.html',{'testmsg': task.faxi(new_benjin, new_rate, new_today, new_enddate)})

#计算公允价值接口
def gongyun(request):
    new_benjin = request.GET.get('benjin')
    new_rate = request.GET.get('rate')
    new_today = request.GET.get('today')
    new_enddate = request.GET.get('enddate')
    new_status = request.GET.get('status')
    import task
    return render(request, 'test_result.html',{'testmsg': task.gongyun(new_benjin, new_rate, new_today, new_enddate,new_status)})


#计算折让比例接口
def rate_zherang(request):
    new_faxi = request.GET.get('faxi')
    new_gongyun = request.GET.get('gongyun')
    new_price = request.GET.get('price')
    import task
    return render(request, 'test_result.html',{'testmsg': task.rate_zherang(new_faxi, new_gongyun, new_price)})



#计算承接人收益率
def shouyilv(request):
    new_borrow_money = request.GET.get('borrow_money')
    new_borrow_month = request.GET.get('borrow_month')
    new_rate = request.GET.get('rate')
    new_price = request.GET.get('price')
    new_manbiao_date = request.GET.get('manbiao_date')
    new_received_money = request.GET.get('received_money')
    import task
    return render(request, 'test_result.html',{'testmsg': task.shouyilv(new_borrow_money, new_borrow_month, new_rate,new_price,new_manbiao_date,new_received_money)})